<?php
require_once('pworks/mvc/FrontController.class.php');
require_once('pworks/mvc/DefaultSystemDataHelper.class.php');
require_once('pworks/mvc/CachedConfigHelper.class.php');
require_once('pworks/common/cache/impl/SimpleCacheHelper.class.php');
require_once('pworks/common/cache/impl/ArrayCache.class.php');
require_once('pworks/common/cache/impl/ApcCache.class.php');
require_once('pworks/util/DebugUtil.class.php');

if (!defined("XPFACE_CONFIG")) {
    exit("XPFACE_CONFIG no defined!!");
}

//============================
// Debug codes for developing
//============================
$debug = isset($_REQUEST['__debug']) ? $_REQUEST['__debug'] : false;
DebugUtil::$enable = $debug; 
$refCache = isset($_REQUEST['__clean_cache'])?$_REQUEST['__clean_cache']:false;
//if ($refCache) apc_clear_cache('user');
apc_clear_cache("user");
try{
    //set config helper
    $confHelper = new CachedConfigHelper();
    $confCacheHelper = new SimpleCacheHelper();
    //$cacheStore = new CacheStore();
    $confCacheHelper->setGroup('xpface-app-conf');
    $confCacheHelper->setCache(new ArrayCache(), 1);
    //$cacheStore->setCache(new ApcCache(), 1);
    $confHelper->setCacheHelper($confCacheHelper);
    //$confHelper->setCacheStore($cacheStore);
    $doConfigCheck = false;
    $confHelper->init(dirname(__FILE__) . '/pworks.xml', $doConfigCheck);
    //$confHelper->init('/data/pms/cs/conf/cs.xml');

    FrontController::$confHelper = $confHelper;

    //set data input helper
    FrontController::$dataHelper = new DefaultSystemDataHelper();

    //set cache helper
    //$appCacheHelper = new CacheStore();
    $appCacheHelper = new SimpleCacheHelper();
    $appCacheHelper->setGroup('xpface-app-obj');
    //$appCacheHelper->setCache(new ApcCache(), 1);
    $appCacheHelper->setCache(new ArrayCache(), 2);
    //$dataHelper = new DefaultSystemDataHelper();

    //FrontController::init($confHelper, $dataHelper, $appCacheHelper);
    FrontController::$cacheHelper = $appCacheHelper;

    //startup
    FrontController::start();

} catch (SystemException $e){
	//if(__DEBUG__){
	if($debug){
		echo "<h3>SystemException</h3>";
		echo "<B>ID:</B>". $e->id;
		echo "<br>";
		echo "<B>TYPE:</B>". $e->type;
		echo "<br>";
		echo '<B>MESSAGE:</B><font size="4" color="red">'; 
		echo $e->message;
		echo "</font>";
		echo "<br>";     
	}
}